package com.yjt.fresh.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yjt.fresh.R;
import com.yjt.fresh.adpater.AdpVpAfterSale;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.fragment.FrgAfterSaleApply;
import com.yjt.fresh.fragment.FrgAfterSaleCheck;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by UPC on 2018/8/11.
 */

public class AtyAfterSale extends BaseSimpleActivity {
    @BindView(R.id.rlAppAtyMyCouponBack)
    RelativeLayout mRlBack;
    @BindView(R.id.tvAppAtyAfterSaleApply)
    TextView mTvApply;
    @BindView(R.id.vAppAtyAfterSaleApply)
    View mVApply;
    @BindView(R.id.rlAppAtyAfterSaleApply)
    RelativeLayout mRlApply;
    @BindView(R.id.tvAppAtyAfterSaleCheck)
    TextView mTvCheck;
    @BindView(R.id.vAppAtyAfterSaleCheck)
    View mVCheck;
    @BindView(R.id.rlAppAtyAfterSaleCheck)
    RelativeLayout mRlCheck;
    @BindView(R.id.vpAppAtyAfterSale)
    ViewPager mVp;
    private int mShowColor;
    private int mNormalColor;

    @Override
    protected int getContentView() {
        return R.layout.app_aty_after_sale;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
        mShowColor = getResources().getColor(R.color.color_43b624);
        mNormalColor = getResources().getColor(R.color.color_333333);
    }

    @Override
    protected void initEvent() {
        initVP();
        initClick();
    }

    private void initClick() {
        mRlApply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                applyShow();
                mVp.setCurrentItem(0);
            }
        });

        mRlCheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkShow();
                mVp.setCurrentItem(1);
            }
        });

        mRlBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initVP() {
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new FrgAfterSaleApply());
        fragments.add(new FrgAfterSaleCheck());
        AdpVpAfterSale adpAfterSale = new AdpVpAfterSale(getSupportFragmentManager(), fragments);
        mVp.setAdapter(adpAfterSale);

        mVp.addOnPageChangeListener(mOnPageChangeListener);
    }

    ViewPager.OnPageChangeListener mOnPageChangeListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            switch (position) {
                case 0:
                    applyShow();
                    break;
                case 1:
                    checkShow();
                    break;
                default:
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    };

    private void checkShow() {
        mTvCheck.setTextColor(mShowColor);
        mVCheck.setVisibility(View.VISIBLE);

        mTvApply.setTextColor(mNormalColor);
        mVApply.setVisibility(View.GONE);
    }

    private void applyShow() {
        mTvApply.setTextColor(mShowColor);
        mVApply.setVisibility(View.VISIBLE);

        mTvCheck.setTextColor(mNormalColor);
        mVCheck.setVisibility(View.GONE);
    }
}
